<template>
  <div>
    <!-- 导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/constanttype' }">常数类型管理</el-breadcrumb-item>
      <el-breadcrumb-item>常数项目管理</el-breadcrumb-item>
      <el-breadcrumb-item>常数项目添加</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
      <el-form-item label="所属常数类别ID" prop="constanttypeid">
        <el-input v-model="ruleForm.constanttypeid"></el-input>
      </el-form-item>
      <el-form-item label="常数项编码" prop="constantcode">
        <el-input v-model="ruleForm.constantcode"></el-input>
      </el-form-item>
      <el-form-item label="常数项名称" prop="constantname">
        <el-input v-model="ruleForm.constantname"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">确认添加</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        constanttypeid: "",
        constantcode: "",
        constantname: "",
        delmark: "1",
      },
      rules: {
        constantcode: [
          {
            required: true,
            message: "常数类编码不能为空",
            trigger: "blur",
          },
        ],
        constantname: [
          {
            required: true,
            message: "常数类名称不能为空",
            trigger: "blur",
          },
        ],
        constanttypeid: [
          {
            required: true,
            message: "所属常数类id不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$http
            .post("http://localhost:8085/his/constantitem/save", this.ruleForm)
            .then(function (resp) {
              console.log(resp);
              if (resp.data == "success") {
                alert("添加成功");
                _this.$router.push("/constanttype");
              }
            });
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
